package com.bbx.wcdemo;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WCMapper extends Mapper<LongWritable, Text,Text, IntWritable> {
    Text text = new Text();
    IntWritable intWritable = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //按行将内容读取进来
        String[] values = value.toString().split(" ");
        for(String v:values){
            text.set(v);
            //拆分后按照 key，value 写出   如 bbx：1，多个不会合并
            context.write(text,intWritable);
        }
    }
}
